package com.dddpeter.app.common;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/** 
* @ClassName: SpringBeanFactoryUtils 
* @Description: 注册Bean获取程序
* @author Peter Lee
* @date 2014年8月11日 下午1:59:53 
*  
*/
public class SpringBeanFactoryUtils implements BeanFactoryAware {
	private static BeanFactory beanFactory = null;
	private static SpringBeanFactoryUtils factoryUtils = null;

	/* (非 Javadoc) 
	* <p>Title: setBeanFactory</p> 
	* <p>Description: </p> 
	* @param beanFactory
	* @throws BeansException 
	* @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory) 
	*/
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		SpringBeanFactoryUtils.beanFactory = beanFactory;
	}
	/** 
	* @Title: getBeanFactory 
	* @Description: 返回Bean的构造器
	* @return    设定文件 
	* @return BeanFactory    返回类型 
	* @throws 
	*/
	public static BeanFactory getBeanFactory() {
		return beanFactory;
	}
	/** 
	* @Title: getInstance 
	* @Description: 本实例初始化方法
	* @return    设定文件 
	* @return SpringBeanFactoryUtils    返回类型 
	* @throws 
	*/
	public static SpringBeanFactoryUtils getInstance() {
		if (factoryUtils == null) {
			factoryUtils = new SpringBeanFactoryUtils();
		}
		return factoryUtils;
	}
	/** 
	* @Title: getBean 
	* @Description: 返回获取到的已经注册到spring中的Bean 
	* @param name
	* @return    设定文件 
	* @return Object    返回类型 
	* @throws 
	*/
	public static Object getBean(String name) {
		return beanFactory.getBean(name);
	}
}
